package priv.conceit.study.book.lambda.chapter3;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * max min
 *
 * 查找最大值,最小值
 *
 * @author Conceit
 * @since 1.0.0, 2021/9/12
 */
@Data
@AllArgsConstructor
public class MinMax {


    private Integer age;
    private String name;
    private Double score;


    public static void main(String[] args) {
        List<MinMax> minMaxs=new ArrayList<>();
        minMaxs.add(new MinMax(1,"zhaoHang",100D));
        minMaxs.add(new MinMax(2,"zhangJin",99D));
        minMaxs.add(new MinMax(3,"suYingNa",98D));
        minMaxs.add(new MinMax(4,"baiXue",97D));
        minMaxs.add(new MinMax(5,"zhangJie",96D));
        minMaxs.add(new MinMax(6,"zhaoJie",95D));
        minMaxs.add(new MinMax(7,"wangWei",95D));
        max(minMaxs);
//        min(minMaxs);

    }

    public static void max(List<MinMax> datas){
//        MinMax minMax=datas.stream().max(Comparator.comparing(MinMax::getScore)).get();
//        MinMax minMax=datas.stream().max(Comparator.comparing(item->item.getScore())).get();
        //如果某一项分值一样，则继续按照其他排序
        //MinMax minMax=datas.stream().max(Comparator.comparing(MinMax::getScore).thenComparing(MinMax::getName)).get();

        //下种写法无法推导
        //MinMax minMax=datas.stream().max(Comparator.comparing(item->item.getScore()).thenComparing(MinMax::getName)).get();
        //可以指定类型
        MinMax minMax=datas.stream().max(Comparator.comparing((MinMax item)->item.getScore()).thenComparing(MinMax::getName)).get();
        System.out.println(minMax);
    }

    public static void min(List<MinMax> datas){

    }

}
